<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>珠峰架构师成长计划</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            珠峰架构师成长计划
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-front.html">30.cms-10-front</a></li><li><a href="../html/30.cms-11-deploy.html">30.cms-11-deploy</a></li><li class="active"><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li><a href="../html/47.oauth.html">47.oauth</a></li><li><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/54.linux.html">54.linux</a></li><li><a href="../html/55.yaml.html">55.yaml</a></li><li><a href="../html/50.ketang2.html">50.ketang2</a></li><li><a href="../html/56.ts.html">56.ts</a></li><li><a href="../html/57.ts_react.html">57.ts_react</a></li><li><a href="../html/58.react-ssr.html">58.react-ssr</a></li><li><a href="../html/59.react-ssr.html">59.react-ssr</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01. Redis简介">1. Redis简介</a></li><li><a href="#t12.Redis 优势">2.Redis 优势</a></li><li><a href="#t23. 安装">3. 安装</a><ul><li><a href="#t33.1 Window下安装">3.1 Window下安装</a></li><li><a href="#t43.2 Mac下安装">3.2 Mac下安装</a></li><li><a href="#t53.3 配置">3.3 配置</a></li></ul></li><li><a href="#t64. 数据类型">4. 数据类型</a><ul><li><a href="#t74.1  字符串">4.1  字符串</a><ul><li><a href="#t84.1.1 SET 设置值">4.1.1 SET 设置值</a></li><li><a href="#t94.1.2 GET 获取值">4.1.2 GET 获取值</a></li><li><a href="#t104.1.3 GETRANGE 获取子串">4.1.3 GETRANGE 获取子串</a></li><li><a href="#t114.1.4 INCR INCRBY 递增">4.1.4 INCR INCRBY 递增</a></li><li><a href="#t124.1.5  键">4.1.5  键</a></li></ul></li><li><a href="#t134.2  哈希值">4.2  哈希值</a><ul><li><a href="#t144.2.1 HSET HMSET 设置值">4.2.1 HSET HMSET 设置值</a></li><li><a href="#t154.2.2 HGET HGETALL 获取值">4.2.2 HGET HGETALL 获取值</a></li><li><a href="#t164.2.3 HDEL key field 删除键">4.2.3 HDEL key field 删除键</a></li><li><a href="#t174.2.3 HKEYS 获取所有的KEYS">4.2.3 HKEYS 获取所有的KEYS</a></li></ul></li><li><a href="#t184.3  列表">4.3  列表</a><ul><li><a href="#t194.3.1 LPUSH RPUSH 添加元素">4.3.1 LPUSH RPUSH 添加元素</a></li><li><a href="#t204.3.2 LRANGE 查看元素">4.3.2 LRANGE 查看元素</a></li><li><a href="#t214.3.3 LPOP RPOP 弹出元素">4.3.3 LPOP RPOP 弹出元素</a></li><li><a href="#t224.3.4 LINDEX ids 1">4.3.4 LINDEX ids 1</a></li><li><a href="#t234.3.5 LLEN key">4.3.5 LLEN key</a></li><li><a href="#t244.3.6 LREM key count value">4.3.6 LREM key count value</a></li></ul></li><li><a href="#t254.4  集合">4.4  集合</a><ul><li><a href="#t264.4.1 SADD 添加">4.4.1 SADD 添加</a></li><li><a href="#t274.4.2 SMEMBERS 查看集合">4.4.2 SMEMBERS 查看集合</a></li><li><a href="#t284.4.3 SCARD 获取集合元素个数">4.4.3 SCARD 获取集合元素个数</a></li><li><a href="#t294.4.4 SREM 删除元素">4.4.4 SREM 删除元素</a></li><li><a href="#t304.4.5 集合运算">4.4.5 集合运算</a></li></ul></li><li><a href="#t314.5  有序集合">4.5  有序集合</a><ul><li><a href="#t324.5.1 ZADD 添加元素">4.5.1 ZADD 添加元素</a></li><li><a href="#t334.5.2 ZCARD 获取有序集合的成员数">4.5.2 ZCARD 获取有序集合的成员数</a></li><li><a href="#t344.5.3 ZRANGE 查看有序集合">4.5.3 ZRANGE 查看有序集合</a></li><li><a href="#t354.5.4 ZREM 移除有序集合中的一个或多个成员">4.5.4 ZREM 移除有序集合中的一个或多个成员</a></li></ul></li></ul></li><li><a href="#t365. Node.js中的使用">5. Node.js中的使用</a></li><li><a href="#t376. Redis发布订阅">6. Redis发布订阅</a></li><li><a href="#t387. Redis事务">7. Redis事务</a></li><li><a href="#t398. 备份与恢复">8. 备份与恢复</a><ul><li><a href="#t408.1 备份">8.1 备份</a></li><li><a href="#t418.2 恢复">8.2 恢复</a></li></ul></li><li><a href="#t428. 安全">8. 安全</a></li></ul>
    </div>
    
    <div class="content markdown-body">
        <h2 id="t01. Redis&#x7B80;&#x4ECB;">1. Redis&#x7B80;&#x4ECB; <a href="#t01. Redis&#x7B80;&#x4ECB;"> # </a></h2>
<p>Redis &#x662F;&#x5B8C;&#x5168;&#x5F00;&#x6E90;&#x514D;&#x8D39;&#x7684;&#xFF0C;&#x9075;&#x5B88;BSD&#x534F;&#x8BAE;&#xFF0C;&#x662F;&#x4E00;&#x4E2A;&#x9AD8;&#x6027;&#x80FD;&#x7684;key-value&#x6570;&#x636E;&#x5E93;&#x3002;</p>
<h2 id="t12.Redis &#x4F18;&#x52BF;">2.Redis &#x4F18;&#x52BF; <a href="#t12.Redis &#x4F18;&#x52BF;"> # </a></h2>
<ul>
<li>&#x6027;&#x80FD;&#x6781;&#x9AD8; &#x2013; Redis&#x80FD;&#x8BFB;&#x7684;&#x901F;&#x5EA6;&#x662F;110000&#x6B21;/s,&#x5199;&#x7684;&#x901F;&#x5EA6;&#x662F;81000&#x6B21;/s &#x3002;</li>
<li>&#x4E30;&#x5BCC;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B; &#x2013; Redis&#x652F;&#x6301;&#x4E8C;&#x8FDB;&#x5236;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x3001;&#x5217;&#x8868;&#x3001;&#x54C8;&#x5E0C;&#x503C;&#x3001;&#x96C6;&#x5408;&#x548C;&#x6709;&#x5E8F;&#x96C6;&#x5408;&#x7B49;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x64CD;&#x4F5C;&#x3002;</li>
<li>&#x539F;&#x5B50;&#x6027; &#x2013; Redis&#x7684;&#x6240;&#x6709;&#x64CD;&#x4F5C;&#x90FD;&#x662F;&#x539F;&#x5B50;&#x6027;&#x7684;&#xFF0C;&#x610F;&#x601D;&#x5C31;&#x662F;&#x8981;&#x4E48;&#x6210;&#x529F;&#x6267;&#x884C;&#x8981;&#x4E48;&#x5931;&#x8D25;&#x5B8C;&#x5168;&#x4E0D;&#x6267;&#x884C;</li>
<li>&#x5355;&#x4E2A;&#x64CD;&#x4F5C;&#x662F;&#x539F;&#x5B50;&#x6027;&#x7684;&#x3002;&#x591A;&#x4E2A;&#x64CD;&#x4F5C;&#x4E5F;&#x652F;&#x6301;&#x4E8B;&#x52A1;&#xFF0C;&#x5373;&#x539F;&#x5B50;&#x6027;&#xFF0C;&#x901A;&#x8FC7;MULTI&#x548C;EXEC&#x6307;&#x4EE4;&#x5305;&#x8D77;&#x6765;&#x3002;</li>
<li>&#x4E30;&#x5BCC;&#x7684;&#x7279;&#x6027; &#x2013; Redis&#x8FD8;&#x652F;&#x6301; &#x53D1;&#x5E03;/&#x8BA2;&#x9605;, &#x901A;&#x77E5;, key &#x8FC7;&#x671F;&#x7B49;&#x7B49;&#x7279;&#x6027;&#x3002;</li>
<li><h2 id="t23. &#x5B89;&#x88C5;">3. &#x5B89;&#x88C5; <a href="#t23. &#x5B89;&#x88C5;"> # </a></h2>
<h3 id="t33.1 Window&#x4E0B;&#x5B89;&#x88C5;">3.1 Window&#x4E0B;&#x5B89;&#x88C5; <a href="#t33.1 Window&#x4E0B;&#x5B89;&#x88C5;"> # </a></h3>
</li>
<li><a href="https://github.com/ServiceStack/redis-windows">redis-windows</a></li>
<li><a href="https://github.com/ServiceStack/redis-windows/raw/master/downloads/redis-latest.zip">redis&#x670D;&#x52A1;&#x7AEF;&#x4E0B;&#x8F7D;</a></li>
<li><a href="https://redisdesktop.com/download">redis&#x5BA2;&#x6237;&#x7AEF;&#x4E0B;&#x8F7D;</a></li>
<li><a href="https://redis.io/">redis&#x5B98;&#x7F51;</a></li>
<li><a href="http://www.redis.cn/documentation.html">redis&#x4E2D;&#x6587;&#x7F51;</a></li>
</ul>
<pre><code class="lang-js">redis-server.exe redis.windows.conf 
 redis-cli.exe -h <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span> -p <span class="hljs-number">6379</span> &#x3002;
</code></pre>
<h3 id="t43.2 Mac&#x4E0B;&#x5B89;&#x88C5;">3.2 Mac&#x4E0B;&#x5B89;&#x88C5; <a href="#t43.2 Mac&#x4E0B;&#x5B89;&#x88C5;"> # </a></h3>
<pre><code class="lang-js">brew install redis
brew services start redis
redis-server /usr/local/etc/redis.conf
</code></pre>
<h3 id="t53.3 &#x914D;&#x7F6E;">3.3 &#x914D;&#x7F6E; <a href="#t53.3 &#x914D;&#x7F6E;"> # </a></h3>
<pre><code class="lang-js">CONFIG GET CONFIG_SETTING_NAME
CONFIG GET port
</code></pre>
<h2 id="t64. &#x6570;&#x636E;&#x7C7B;&#x578B;">4. &#x6570;&#x636E;&#x7C7B;&#x578B; <a href="#t64. &#x6570;&#x636E;&#x7C7B;&#x578B;"> # </a></h2>
<ul>
<li>&#x5B57;&#x7B26;&#x4E32;</li>
<li>&#x54C8;&#x5E0C;&#x503C;</li>
<li>&#x94FE;&#x8868;</li>
<li>&#x96C6;&#x5408;</li>
<li>&#x6709;&#x5E8F;&#x5217;&#x8868;</li>
</ul>
<h3 id="t74.1  &#x5B57;&#x7B26;&#x4E32;">4.1  &#x5B57;&#x7B26;&#x4E32; <a href="#t74.1  &#x5B57;&#x7B26;&#x4E32;"> # </a></h3>
<p>&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x6700;&#x57FA;&#x672C;&#x7684;&#x7C7B;&#x578B;,&#x4E00;&#x4E2A;key&#x5BF9;&#x5E94;&#x4E00;&#x4E2A;value</p>
<h4 id="t84.1.1 SET &#x8BBE;&#x7F6E;&#x503C;">4.1.1 SET &#x8BBE;&#x7F6E;&#x503C; <a href="#t84.1.1 SET &#x8BBE;&#x7F6E;&#x503C;"> # </a></h4>
<pre><code class="lang-js">SET name zfpx
</code></pre>
<h4 id="t94.1.2 GET &#x83B7;&#x53D6;&#x503C;">4.1.2 GET &#x83B7;&#x53D6;&#x503C; <a href="#t94.1.2 GET &#x83B7;&#x53D6;&#x503C;"> # </a></h4>
<pre><code class="lang-js">GET name
</code></pre>
<h4 id="t104.1.3 GETRANGE &#x83B7;&#x53D6;&#x5B50;&#x4E32;">4.1.3 GETRANGE &#x83B7;&#x53D6;&#x5B50;&#x4E32; <a href="#t104.1.3 GETRANGE &#x83B7;&#x53D6;&#x5B50;&#x4E32;"> # </a></h4>
<pre><code class="lang-js">GETRANGE key start end 
getrange name <span class="hljs-number">1</span> <span class="hljs-number">2</span>
<span class="hljs-string">&quot;fp&quot;</span>
</code></pre>
<h4 id="t114.1.4 INCR INCRBY &#x9012;&#x589E;">4.1.4 INCR INCRBY &#x9012;&#x589E; <a href="#t114.1.4 INCR INCRBY &#x9012;&#x589E;"> # </a></h4>
<pre><code class="lang-js">SET age <span class="hljs-number">1</span>
INCR age
INCRBY age <span class="hljs-number">6</span>
DECR age
DECRBY age  <span class="hljs-number">9</span>
</code></pre>
<h4 id="t124.1.5  &#x952E;">4.1.5  &#x952E; <a href="#t124.1.5  &#x952E;"> # </a></h4>
<pre><code class="lang-js">DEL key &#x5220;&#x9664; key
DEL user 
EXISTS key &#x5224;&#x65AD;&#x4E00;&#x4E2A;key&#x662F;&#x5426;&#x5B58;&#x5728;
EXISTS user 
EXPIRE key seconds  &#x8BBE;&#x7F6E;&#x8FC7;&#x671F;&#x65F6;&#x95F4;
EXPIRE user <span class="hljs-number">10</span> 
TTL key &#x4EE5;&#x79D2;&#x4E3A;&#x5355;&#x4F4D;&#x8FD4;&#x56DE;&#x7ED9;&#x5B9A;key&#x7684;&#x5269;&#x4F59;&#x751F;&#x5B58;&#x65F6;&#x95F4;
TTL user 
TYPE key &#x8FD4;&#x56DE;key&#x6240;&#x5B58;&#x50A8;&#x7684;&#x503C;&#x7684;&#x7C7B;&#x578B;
TYPE user
</code></pre>
<h3 id="t134.2  &#x54C8;&#x5E0C;&#x503C;">4.2  &#x54C8;&#x5E0C;&#x503C; <a href="#t134.2  &#x54C8;&#x5E0C;&#x503C;"> # </a></h3>
<p>&#x54C8;&#x5E0C;&#x503C;&#x662F;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x7C7B;&#x578B;&#x7684;Key&#x548C;&#x503C;&#x7684;&#x6620;&#x5C04;&#x8868;,&#x7279;&#x522B;&#x9002;&#x5408;&#x7528;&#x4E8E;&#x5B58;&#x50A8;&#x5BF9;&#x8C61;&#x3002;</p>
<h4 id="t144.2.1 HSET HMSET &#x8BBE;&#x7F6E;&#x503C;">4.2.1 HSET HMSET &#x8BBE;&#x7F6E;&#x503C; <a href="#t144.2.1 HSET HMSET &#x8BBE;&#x7F6E;&#x503C;"> # </a></h4>
<pre><code class="lang-js">HSET person name &#x8BBE;&#x7F6E;&#x5355;&#x4E2A;&#x503C;
HMSET user name zfpx age <span class="hljs-number">9</span>  &#x8BBE;&#x7F6E;&#x591A;&#x4E2A;&#x503C;
</code></pre>
<h4 id="t154.2.2 HGET HGETALL &#x83B7;&#x53D6;&#x503C;">4.2.2 HGET HGETALL &#x83B7;&#x53D6;&#x503C; <a href="#t154.2.2 HGET HGETALL &#x83B7;&#x53D6;&#x503C;"> # </a></h4>
<pre><code class="lang-js">HGET user name &#x83B7;&#x53D6;&#x5355;&#x4E2A;&#x503C;
HMGET user name age &#x83B7;&#x53D6;&#x591A;&#x4E2A;&#x503C;
HGETALL user &#x83B7;&#x53D6;&#x591A;&#x6709;&#x503C;
</code></pre>
<h4 id="t164.2.3 HDEL key field &#x5220;&#x9664;&#x952E;">4.2.3 HDEL key field &#x5220;&#x9664;&#x952E; <a href="#t164.2.3 HDEL key field &#x5220;&#x9664;&#x952E;"> # </a></h4>
<pre><code class="lang-js">HDEL key field
HDEL user name
HGETALL user
</code></pre>
<h4 id="t174.2.3 HKEYS &#x83B7;&#x53D6;&#x6240;&#x6709;&#x7684;KEYS">4.2.3 HKEYS &#x83B7;&#x53D6;&#x6240;&#x6709;&#x7684;KEYS <a href="#t174.2.3 HKEYS &#x83B7;&#x53D6;&#x6240;&#x6709;&#x7684;KEYS"> # </a></h4>
<pre><code class="lang-js"> HKEYS user
</code></pre>
<h3 id="t184.3  &#x5217;&#x8868;">4.3  &#x5217;&#x8868; <a href="#t184.3  &#x5217;&#x8868;"> # </a></h3>
<p>&#x5217;&#x8868;&#x662F;&#x7B80;&#x5355;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x5217;&#x8868;&#xFF0C;&#x6309;&#x7167;&#x63D2;&#x5165;&#x987A;&#x5E8F;&#x6392;&#x5E8F;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x5230;&#x5217;&#x8868;&#x7684;&#x5934;&#x90E8;&#xFF08;&#x5DE6;&#x8FB9;&#xFF09;&#x6216;&#x8005;&#x5C3E;&#x90E8;&#xFF08;&#x53F3;&#x8FB9;&#xFF09;&#x3002;</p>
<h4 id="t194.3.1 LPUSH RPUSH &#x6DFB;&#x52A0;&#x5143;&#x7D20;">4.3.1 LPUSH RPUSH &#x6DFB;&#x52A0;&#x5143;&#x7D20; <a href="#t194.3.1 LPUSH RPUSH &#x6DFB;&#x52A0;&#x5143;&#x7D20;"> # </a></h4>
<p>&#x8FD4;&#x56DE;&#x5217;&#x8868;&#x7684;&#x957F;&#x5EA6;</p>
<pre><code class="lang-js">LPUSH ids <span class="hljs-number">2</span>
LPUSH ids <span class="hljs-number">1</span>
RPUSH ids <span class="hljs-number">3</span>
RPUSH ids <span class="hljs-number">4</span>
RPUSH ids  <span class="hljs-number">5</span> <span class="hljs-number">6</span> 
</code></pre>
<h4 id="t204.3.2 LRANGE &#x67E5;&#x770B;&#x5143;&#x7D20;">4.3.2 LRANGE &#x67E5;&#x770B;&#x5143;&#x7D20; <a href="#t204.3.2 LRANGE &#x67E5;&#x770B;&#x5143;&#x7D20;"> # </a></h4>
<pre><code class="lang-js">LRANGE ids <span class="hljs-number">0</span> <span class="hljs-number">2</span>
LRANGE ids <span class="hljs-number">0</span> <span class="hljs-number">-1</span>
</code></pre>
<h4 id="t214.3.3 LPOP RPOP &#x5F39;&#x51FA;&#x5143;&#x7D20;">4.3.3 LPOP RPOP &#x5F39;&#x51FA;&#x5143;&#x7D20; <a href="#t214.3.3 LPOP RPOP &#x5F39;&#x51FA;&#x5143;&#x7D20;"> # </a></h4>
<p>&#x67E5;&#x770B;&#x5E76;&#x5220;&#x9664;</p>
<pre><code class="lang-js">LPOP ids 
RPOP ids
</code></pre>
<h4 id="t224.3.4 LINDEX ids 1">4.3.4 LINDEX ids 1 <a href="#t224.3.4 LINDEX ids 1"> # </a></h4>
<p>&#x901A;&#x8FC7;&#x7D22;&#x5F15;&#x83B7;&#x53D6;&#x5217;&#x8868;&#x4E2D;&#x7684;&#x5143;&#x7D20;</p>
<pre><code class="lang-js">LINDEX ids <span class="hljs-number">0</span>
</code></pre>
<h4 id="t234.3.5 LLEN key">4.3.5 LLEN key <a href="#t234.3.5 LLEN key"> # </a></h4>
<p>&#x83B7;&#x53D6;&#x5217;&#x8868;&#x957F;&#x5EA6;</p>
<pre><code class="lang-js">LLEN ids
</code></pre>
<h4 id="t244.3.6 LREM key count value">4.3.6 LREM key count value <a href="#t244.3.6 LREM key count value"> # </a></h4>
<p>&#x79FB;&#x9664;&#x5217;&#x8868;&#x5143;&#x7D20;</p>
<ul>
<li>count &gt; 0 : &#x4ECE;&#x8868;&#x5934;&#x5F00;&#x59CB;&#x5411;&#x8868;&#x5C3E;&#x641C;&#x7D22;&#xFF0C;&#x79FB;&#x9664;&#x4E0E; VALUE &#x76F8;&#x7B49;&#x7684;&#x5143;&#x7D20;&#xFF0C;&#x6570;&#x91CF;&#x4E3A; COUNT &#x3002;</li>
<li>count &lt; 0 : &#x4ECE;&#x8868;&#x5C3E;&#x5F00;&#x59CB;&#x5411;&#x8868;&#x5934;&#x641C;&#x7D22;&#xFF0C;&#x79FB;&#x9664;&#x4E0E; VALUE &#x76F8;&#x7B49;&#x7684;&#x5143;&#x7D20;&#xFF0C;&#x6570;&#x91CF;&#x4E3A; COUNT &#x7684;&#x7EDD;&#x5BF9;&#x503C;&#x3002;</li>
<li>count = 0 : &#x79FB;&#x9664;&#x8868;&#x4E2D;&#x6240;&#x6709;&#x4E0E; VALUE &#x76F8;&#x7B49;&#x7684;&#x503C;&#x3002;<pre><code class="lang-js">LREM ids count value
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; lpush my <span class="hljs-number">1</span>
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; lpush my <span class="hljs-number">2</span>
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; lpush my <span class="hljs-number">2</span>
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; lpush my <span class="hljs-number">2</span>
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; lpush my <span class="hljs-number">3</span>
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; lrange my <span class="hljs-number">0</span> <span class="hljs-number">-1</span>
<span class="hljs-number">1</span>) <span class="hljs-string">&quot;3&quot;</span>
<span class="hljs-number">2</span>) <span class="hljs-string">&quot;2&quot;</span>
<span class="hljs-number">3</span>) <span class="hljs-string">&quot;2&quot;</span>
<span class="hljs-number">4</span>) <span class="hljs-string">&quot;2&quot;</span>
<span class="hljs-number">5</span>) <span class="hljs-string">&quot;1&quot;</span>
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; LREM my <span class="hljs-number">2</span> <span class="hljs-number">2</span>
(integer) <span class="hljs-number">2</span>
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; lrange my <span class="hljs-number">0</span> <span class="hljs-number">-1</span>
<span class="hljs-number">1</span>) <span class="hljs-string">&quot;3&quot;</span>
<span class="hljs-number">2</span>) <span class="hljs-string">&quot;2&quot;</span>
<span class="hljs-number">3</span>) <span class="hljs-string">&quot;1&quot;</span>
</code></pre>
</li>
</ul>
<h3 id="t254.4  &#x96C6;&#x5408;">4.4  &#x96C6;&#x5408; <a href="#t254.4  &#x96C6;&#x5408;"> # </a></h3>
<p>&#x96C6;&#x5408;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#x7C7B;&#x578B;&#x7684;&#x65E0;&#x5E8F;&#x96C6;&#x5408;</p>
<h4 id="t264.4.1 SADD &#x6DFB;&#x52A0;">4.4.1 SADD &#x6DFB;&#x52A0; <a href="#t264.4.1 SADD &#x6DFB;&#x52A0;"> # </a></h4>
<p>&#x5982;&#x679C;&#x96C6;&#x5408;&#x4E2D;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x6307;&#x5B9A;&#x7684;&#x5143;&#x7D20;&#x5219;&#x8FD4;&#x56DE;0,&#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#x5219;&#x6DFB;&#x52A0;&#x6210;&#x529F;&#x8FD4;&#x56DE;1</p>
<pre><code class="lang-js">SADD tags <span class="hljs-number">1</span>
SADD tags <span class="hljs-number">2</span>
SADD tags <span class="hljs-number">2</span>
SADD tags <span class="hljs-number">3</span>
SADD tags  <span class="hljs-number">4</span> <span class="hljs-number">5</span> <span class="hljs-number">6</span> 
SMEMBERS tags
</code></pre>
<h4 id="t274.4.2 SMEMBERS &#x67E5;&#x770B;&#x96C6;&#x5408;">4.4.2 SMEMBERS &#x67E5;&#x770B;&#x96C6;&#x5408; <a href="#t274.4.2 SMEMBERS &#x67E5;&#x770B;&#x96C6;&#x5408;"> # </a></h4>
<pre><code class="lang-js">SMEMBERS tags
</code></pre>
<h4 id="t284.4.3 SCARD &#x83B7;&#x53D6;&#x96C6;&#x5408;&#x5143;&#x7D20;&#x4E2A;&#x6570;">4.4.3 SCARD &#x83B7;&#x53D6;&#x96C6;&#x5408;&#x5143;&#x7D20;&#x4E2A;&#x6570; <a href="#t284.4.3 SCARD &#x83B7;&#x53D6;&#x96C6;&#x5408;&#x5143;&#x7D20;&#x4E2A;&#x6570;"> # </a></h4>
<pre><code class="lang-js">SCARD tags
</code></pre>
<h4 id="t294.4.4 SREM &#x5220;&#x9664;&#x5143;&#x7D20;">4.4.4 SREM &#x5220;&#x9664;&#x5143;&#x7D20; <a href="#t294.4.4 SREM &#x5220;&#x9664;&#x5143;&#x7D20;"> # </a></h4>
<pre><code class="lang-js">SREM tags member
SREM tags <span class="hljs-number">4</span>
SMEMBERS tags
</code></pre>
<h4 id="t304.4.5 &#x96C6;&#x5408;&#x8FD0;&#x7B97;">4.4.5 &#x96C6;&#x5408;&#x8FD0;&#x7B97; <a href="#t304.4.5 &#x96C6;&#x5408;&#x8FD0;&#x7B97;"> # </a></h4>
<pre><code class="lang-js">SADD A <span class="hljs-number">1</span> <span class="hljs-number">2</span> <span class="hljs-number">3</span> 
SADD B <span class="hljs-number">2</span> <span class="hljs-number">3</span> <span class="hljs-number">4</span>
SINTER A B &#x4EA4;&#x96C6;
SDIFF A B &#x5DEE;&#x96C6;
SUNION A B &#x5E76;&#x96C6;
</code></pre>
<h3 id="t314.5  &#x6709;&#x5E8F;&#x96C6;&#x5408;">4.5  &#x6709;&#x5E8F;&#x96C6;&#x5408; <a href="#t314.5  &#x6709;&#x5E8F;&#x96C6;&#x5408;"> # </a></h3>
<p>&#x6709;&#x5E8F;&#x96C6;&#x5408;&#x548C;&#x96C6;&#x5408;&#x4E00;&#x6837;&#x4E5F;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x96C6;&#x5408;&#xFF0C;&#x800C;&#x4E14;&#x4E0D;&#x80FD;&#x91CD;&#x590D;
&#x4E0D;&#x540C;&#x4E4B;&#x5916;&#x662F;&#x6BCF;&#x4E2A;&#x96C6;&#x5408;&#x90FD;&#x4F1A;&#x5173;&#x8054;&#x4E00;&#x4E2A;double&#x7C7B;&#x578B;&#x7684;&#x5206;&#x6570;&#xFF0C;redis&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8FD9;&#x4E2A;&#x5206;&#x7C7B;&#x6765;&#x4E3A;&#x96C6;&#x5408;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x8FDB;&#x884C;&#x4ECE;&#x5C0F;&#x5230;&#x5927;&#x6392;&#x5E8F;,&#x5143;&#x7D20;&#x4E0D;&#x80FD;&#x91CD;&#x590D;&#xFF0C;&#x4F46;&#x5206;&#x6570;&#x53EF;&#x4EE5;&#x91CD;&#x590D;</p>
<h4 id="t324.5.1 ZADD &#x6DFB;&#x52A0;&#x5143;&#x7D20;">4.5.1 ZADD &#x6DFB;&#x52A0;&#x5143;&#x7D20; <a href="#t324.5.1 ZADD &#x6DFB;&#x52A0;&#x5143;&#x7D20;"> # </a></h4>
<pre><code class="lang-js">ZADD key score1 member1 [score2 member2] 

ZADD levels <span class="hljs-number">1</span> one
ZADD levels <span class="hljs-number">2</span> two
ZADD levels <span class="hljs-number">3</span> three
ZADD levels <span class="hljs-number">4</span> four
</code></pre>
<h4 id="t334.5.2 ZCARD &#x83B7;&#x53D6;&#x6709;&#x5E8F;&#x96C6;&#x5408;&#x7684;&#x6210;&#x5458;&#x6570;">4.5.2 ZCARD &#x83B7;&#x53D6;&#x6709;&#x5E8F;&#x96C6;&#x5408;&#x7684;&#x6210;&#x5458;&#x6570; <a href="#t334.5.2 ZCARD &#x83B7;&#x53D6;&#x6709;&#x5E8F;&#x96C6;&#x5408;&#x7684;&#x6210;&#x5458;&#x6570;"> # </a></h4>
<pre><code class="lang-js">ZCARD key
ZCARD levels
</code></pre>
<h4 id="t344.5.3 ZRANGE &#x67E5;&#x770B;&#x6709;&#x5E8F;&#x96C6;&#x5408;">4.5.3 ZRANGE &#x67E5;&#x770B;&#x6709;&#x5E8F;&#x96C6;&#x5408; <a href="#t344.5.3 ZRANGE &#x67E5;&#x770B;&#x6709;&#x5E8F;&#x96C6;&#x5408;"> # </a></h4>
<pre><code class="lang-js">ZRANGE levels  <span class="hljs-number">0</span> <span class="hljs-number">-1</span> &#x6309;&#x8303;&#x56F4;&#x67E5;&#x770B;
ZRANGE levels  <span class="hljs-number">0</span> <span class="hljs-number">2</span> WITHSCORES &#x6309;&#x8303;&#x56F4;&#x67E5;&#x770B;&#xFF0C;&#x5E76;&#x663E;&#x793A;&#x5206;&#x6570;
</code></pre>
<h4 id="t354.5.4 ZREM &#x79FB;&#x9664;&#x6709;&#x5E8F;&#x96C6;&#x5408;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x6210;&#x5458;">4.5.4 ZREM &#x79FB;&#x9664;&#x6709;&#x5E8F;&#x96C6;&#x5408;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x6210;&#x5458; <a href="#t354.5.4 ZREM &#x79FB;&#x9664;&#x6709;&#x5E8F;&#x96C6;&#x5408;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x6210;&#x5458;"> # </a></h4>
<pre><code class="lang-js">ZREM key member [member ...] 
ZADD levels <span class="hljs-number">1</span> one
ZADD levels <span class="hljs-number">2</span> two
ZREM levels one
 ZRANGE levels  <span class="hljs-number">0</span> <span class="hljs-number">-1</span>
</code></pre>
<h2 id="t365. Node.js&#x4E2D;&#x7684;&#x4F7F;&#x7528;">5. Node.js&#x4E2D;&#x7684;&#x4F7F;&#x7528; <a href="#t365. Node.js&#x4E2D;&#x7684;&#x4F7F;&#x7528;"> # </a></h2>
<ul>
<li><a href="https://www.npmjs.com/package/redis">redis</a></li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> redis = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;redis&apos;</span>);
<span class="hljs-keyword">let</span> client = redis.createClient(<span class="hljs-number">6379</span>, <span class="hljs-string">&apos;127.0.0.1&apos;</span>);
client.on(<span class="hljs-string">&apos;error&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">error</span>) </span>{
    <span class="hljs-built_in">console</span>.error(error);
});
<span class="hljs-comment">//1. &#x5B57;&#x7B26;&#x4E32;&#x7C7B;&#x578B;</span>
client.set(<span class="hljs-string">&apos;name&apos;</span>, <span class="hljs-string">&apos;zfpx&apos;</span>, redis.print);
client.get(<span class="hljs-string">&apos;name&apos;</span>, redis.print);
<span class="hljs-comment">//2. &#x96C6;&#x5408;</span>
client.hset(<span class="hljs-string">&apos;user&apos;</span>, <span class="hljs-string">&apos;name&apos;</span>, <span class="hljs-string">&apos;zfpx&apos;</span>, redis.print);
client.hset(<span class="hljs-string">&apos;user&apos;</span>, <span class="hljs-string">&apos;age&apos;</span>, <span class="hljs-string">&apos;8&apos;</span>, redis.print);
client.hget(<span class="hljs-string">&apos;user&apos;</span>, <span class="hljs-string">&apos;age&apos;</span>, redis.print);
client.hkeys(<span class="hljs-string">&apos;user&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err, replies</span>) </span>{
    replies.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">item, index, items</span>) </span>{
        client.hget(<span class="hljs-string">&apos;user&apos;</span>, item, redis.print);
    });
});
</code></pre>
<h2 id="t376. Redis&#x53D1;&#x5E03;&#x8BA2;&#x9605;">6. Redis&#x53D1;&#x5E03;&#x8BA2;&#x9605; <a href="#t376. Redis&#x53D1;&#x5E03;&#x8BA2;&#x9605;"> # </a></h2>
<p>Redis &#x53D1;&#x5E03;&#x8BA2;&#x9605;&#x662F;&#x4E00;&#x79CD;&#x6D88;&#x606F;&#x901A;&#x4FE1;&#x6A21;&#x5F0F;&#xFF1A;&#x53D1;&#x9001;&#x8005;&#x53D1;&#x9001;&#x6D88;&#x606F;&#xFF0C;&#x8BA2;&#x9605;&#x8005;&#x63A5;&#x6536;&#x6D88;&#x606F;&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x53EF;&#x4EE5;&#x8BA2;&#x9605;&#x4EFB;&#x610F;&#x6570;&#x91CF;&#x7684;&#x9891;&#x9053;&#x3002;</p>
<p><img src="http://img.zhufengpeixun.cn/redissubscribe.jpg" alt="redissubscribe"></p>
<pre><code class="lang-js">SUBSCRIBE chat
PUBLISH chat zfpx
</code></pre>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> client1 = redis.createClient(<span class="hljs-number">6379</span>, <span class="hljs-string">&apos;127.0.0.1&apos;</span>);
<span class="hljs-keyword">let</span> client2 = redis.createClient(<span class="hljs-number">6379</span>, <span class="hljs-string">&apos;127.0.0.1&apos;</span>);
<span class="hljs-keyword">let</span> count = <span class="hljs-number">0</span>;
client1.subscribe(<span class="hljs-string">&apos;food&apos;</span>);
client1.subscribe(<span class="hljs-string">&apos;drink&apos;</span>);
client1.on(<span class="hljs-string">&apos;message&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">channel, message</span>) </span>{
    <span class="hljs-built_in">console</span>.log(channel, message);
    client1.unsubscribe(<span class="hljs-string">&apos;food&apos;</span>);
});

client2.publish(<span class="hljs-string">&apos;food&apos;</span>, <span class="hljs-string">&apos;&#x9762;&#x5305;&apos;</span>);
client2.publish(<span class="hljs-string">&apos;drink&apos;</span>, <span class="hljs-string">&apos;&#x6854;&#x6C41;&apos;</span>);
setTimeout(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
    client2.publish(<span class="hljs-string">&apos;food&apos;</span>, <span class="hljs-string">&apos;&#x9762;&#x5305;2&apos;</span>);
    client2.publish(<span class="hljs-string">&apos;drink&apos;</span>, <span class="hljs-string">&apos;&#x6854;&#x6C41;2&apos;</span>);
}, <span class="hljs-number">2000</span>);
</code></pre>
<h2 id="t387. Redis&#x4E8B;&#x52A1;">7. Redis&#x4E8B;&#x52A1; <a href="#t387. Redis&#x4E8B;&#x52A1;"> # </a></h2>
<p>Redis &#x4E8B;&#x52A1;&#x53EF;&#x4EE5;&#x4E00;&#x6B21;&#x6267;&#x884C;&#x591A;&#x4E2A;&#x547D;&#x4EE4;</p>
<ul>
<li>&#x591A;&#x4E2A;&#x547D;&#x4EE4;&#x53EF;&#x4EE5;&#x5728;&#x6267;&#x884C;EXEC&#x547D;&#x4EE4;&#x4E4B;&#x524D;&#x653E;&#x5165;&#x7F13;&#x5B58;&#x961F;&#x5217;</li>
<li>&#x6536;&#x5230;EXEC&#x547D;&#x4EE4;&#x540E;&#x4F1A;&#x5C06;&#x7F13;&#x5B58;&#x961F;&#x5217;&#x6267;&#x884C;</li>
<li>&#x5728;&#x6267;&#x884C;&#x4E8B;&#x52A1;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x65B0;&#x63D0;&#x4EA4;&#x7684;&#x5E76;&#x4E0D;&#x80FD;&#x88AB;&#x63D2;&#x5165;&#x5230;&#x4E8B;&#x52A1;&#x6267;&#x884C;&#x5E8F;&#x5217;&#x4E2D;</li>
<li><p>DISCARD &#x53EF;&#x4EE5;&#x53D6;&#x6D88;&#x4E8B;&#x52A1;&#xFF0C;&#x653E;&#x5F03;&#x6267;&#x884C;&#x4E8B;&#x52A1;&#x5757;&#x5185;&#x7684;&#x6240;&#x6709;&#x547D;&#x4EE4;</p>
<pre><code class="lang-js"><span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; MULTI
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; SET account1 <span class="hljs-number">1</span>
QUEUED
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; SET account2 <span class="hljs-number">3</span>
QUEUED
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; EXEC
<span class="hljs-number">1</span>) OK
<span class="hljs-number">2</span>) OK
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; GET account1
<span class="hljs-string">&quot;1&quot;</span>
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; GET account2
<span class="hljs-string">&quot;3&quot;</span>
</code></pre>
</li>
<li><p>&#x5355;&#x4E2A; Redis &#x547D;&#x4EE4;&#x7684;&#x6267;&#x884C;&#x662F;&#x539F;&#x5B50;&#x6027;&#x7684;&#xFF0C;&#x4F46; Redis &#x6CA1;&#x6709;&#x5728;&#x4E8B;&#x52A1;&#x4E0A;&#x589E;&#x52A0;&#x4EFB;&#x4F55;&#x7EF4;&#x6301;&#x539F;&#x5B50;&#x6027;&#x7684;&#x673A;&#x5236;&#xFF0C;&#x6240;&#x4EE5; Redis &#x4E8B;&#x52A1;&#x7684;&#x6267;&#x884C;&#x5E76;&#x4E0D;&#x662F;&#x539F;&#x5B50;&#x6027;&#x7684;</p>
</li>
<li>&#x4E8B;&#x52A1;&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x4E3A;&#x4E00;&#x4E2A;&#x6253;&#x5305;&#x7684;&#x6279;&#x91CF;&#x6267;&#x884C;&#x811A;&#x672C;&#xFF0C;&#x4F46;&#x6279;&#x91CF;&#x6307;&#x4EE4;&#x5E76;&#x975E;&#x539F;&#x5B50;&#x5316;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x4E2D;&#x95F4;&#x67D0;&#x6761;&#x6307;&#x4EE4;&#x7684;&#x5931;&#x8D25;&#x4E0D;&#x4F1A;&#x5BFC;&#x81F4;&#x524D;&#x9762;&#x5DF2;&#x505A;&#x6307;&#x4EE4;&#x7684;&#x56DE;&#x6EDA;&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x9020;&#x6210;&#x540E;&#x7EED;&#x7684;&#x6307;&#x4EE4;&#x4E0D;&#x505A;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> redis = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;redis&apos;</span>);
<span class="hljs-keyword">let</span> client = redis.createClient(<span class="hljs-number">6379</span>, <span class="hljs-string">&apos;127.0.0.1&apos;</span>);
client.multi().hset(<span class="hljs-string">&apos;user2&apos;</span>, <span class="hljs-string">&apos;name2&apos;</span>, <span class="hljs-string">&apos;zfpx2&apos;</span>).hset(<span class="hljs-string">&apos;user2&apos;</span>, <span class="hljs-string">&apos;age2&apos;</span>, <span class="hljs-string">&apos;92&apos;</span>).exec(redis.print);
</code></pre>
<h2 id="t398. &#x5907;&#x4EFD;&#x4E0E;&#x6062;&#x590D;">8. &#x5907;&#x4EFD;&#x4E0E;&#x6062;&#x590D; <a href="#t398. &#x5907;&#x4EFD;&#x4E0E;&#x6062;&#x590D;"> # </a></h2>
<h3 id="t408.1 &#x5907;&#x4EFD;">8.1 &#x5907;&#x4EFD; <a href="#t408.1 &#x5907;&#x4EFD;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; SAVE
OK
</code></pre>
<blockquote>
<p>&#x8BE5;&#x547D;&#x4EE4;&#x5C06;&#x5728; redis &#x5B89;&#x88C5;&#x76EE;&#x5F55;&#x4E2D;&#x521B;&#x5EFA;dump.rdb&#x6587;&#x4EF6;&#x3002;</p>
</blockquote>
<h3 id="t418.2 &#x6062;&#x590D;">8.2 &#x6062;&#x590D; <a href="#t418.2 &#x6062;&#x590D;"> # </a></h3>
<p>&#x5C06;&#x5907;&#x4EFD;&#x6587;&#x4EF6; (dump.rdb) &#x79FB;&#x52A8;&#x5230; redis &#x5B89;&#x88C5;&#x76EE;&#x5F55;&#x5E76;&#x542F;&#x52A8;&#x670D;&#x52A1;</p>
<pre><code class="lang-js"> CONFIG GET dir
 BGSAVE
</code></pre>
<h2 id="t428. &#x5B89;&#x5168;">8. &#x5B89;&#x5168; <a href="#t428. &#x5B89;&#x5168;"> # </a></h2>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7; redis &#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x8BBE;&#x7F6E;&#x5BC6;&#x7801;&#x53C2;&#x6570;&#xFF0C;&#x8FD9;&#x6837;&#x5BA2;&#x6237;&#x7AEF;&#x8FDE;&#x63A5;&#x5230; redis &#x670D;&#x52A1;&#x5C31;&#x9700;&#x8981;&#x5BC6;&#x7801;&#x9A8C;&#x8BC1;&#xFF0C;&#x8FD9;&#x6837;&#x53EF;&#x4EE5;&#x8BA9;&#x4F60;&#x7684; redis &#x670D;&#x52A1;&#x66F4;&#x5B89;&#x5168;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; CONFIG get requirepass
<span class="hljs-number">1</span>) <span class="hljs-string">&quot;requirepass&quot;</span>
<span class="hljs-number">2</span>) <span class="hljs-string">&quot;&quot;</span>
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; CONFIG set requirepass <span class="hljs-string">&apos;zfpx&apos;</span>
OK
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; CONFIG get requirepass
(error) NOAUTH Authentication required.
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; AUTH zfpx
OK
<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>:<span class="hljs-number">6379</span>&gt; CONFIG get requirepass
</code></pre>

        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
